package com.nut.article.service.impl;

import com.nut.article.common.Result;
import com.nut.article.entity.Tag;
import com.nut.article.entity.TagArticle;
import com.nut.article.mapper.TagArticleMapper;
import com.nut.article.service.TagArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Set;

public class TagArticleServiceImpl implements TagArticleService {

    @Autowired
    private TagArticleMapper tagArticleMapper;

    @Override
    public Result<List<Tag>> getListByArticleId(Integer articleId) {
        List<Tag> tags = tagArticleMapper.selectListByArticleId(articleId);
        return Result.ok(tags);
    }

    @Override
    public Result add(Integer articleId, Integer tagId) {
        TagArticle tagArticle = new TagArticle();
        tagArticle.setArticleId(articleId);
        tagArticle.setTagId(tagId);
        tagArticleMapper.insert(tagArticle);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        for (Integer id : ids) {
            tagArticleMapper.deleteById(id);
        }
        return Result.ok();
    }
}
